<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var targetCodes = document.getElementsByName("targetCode");
		var grossProfit = document.getElementById("grossProfit");
		
		var maxLimitCodes = document.getElementsByName("maxLimitCode");
		var unifyLimit = document.getElementById("unifyLimit");
		var targetLimit = document.getElementById("targetLimit");
		var roleLimits = document.getElementsByName("roleLimit");
		
		var expUser = document.getElementById("isExpUser");
		var userIds = document.getElementsByName("userId");
		
		if(targetCodes[2].checked 
			&& (grossProfit.value == "")){
			alert("<fmt:message key='astype.message.contract'/>");
			return false;
		}
		
		if(maxLimitCodes[0].checked 
			&& unifyLimit.value == ""){
			alert("<fmt:message key='astype.message.unify'/>");	
			return false;
		}
		
		if(maxLimitCodes[1].checked 
			&& targetLimit.value == ""){
			alert("<fmt:message key='astype.message.target'/>");
			return false;		
		}
		
		if(maxLimitCodes[2].checked){
			for(var i = 0; i < roleLimits.length; i++){
				if(roleLimits[i].value == ""){
					alert("<fmt:message key='astype.message.role'/>");
					return false;
				}
			}
		}
		
		if(expUser.checked){
			var sign = 0;
			for(var i = 0; i < userIds.length; i++){
				if(userIds[i].checked){
					sign = sign + 1;
				}
			}
			if(sign <= 0){
				alert("请选择例外用户！");
				return false;
			}
		}
		
		return true;
	}

	function switchSysBar(rObj,id){
		var obj = document.getElementById(id);
		var rObjs = document.getElementsByName("maxLimitCode");
		if(obj.style.display == "none" && rObj.checked && rObj == rObjs[2]){
			document.getElementById(id).style.display = "block";
		}else if(rObj.checked && rObj != rObjs[2]){
			document.getElementById(id).style.display = "none";
		}
	}
	
	function switchSysBar2(obj,id){
		var tObj = document.getElementById(id);
		if(tObj.style.display == "none" && obj.checked){
			document.getElementById(id).style.display = "block";
		}else{
			document.getElementById(id).style.display = "none";
		}
	}
	
	function save(){
		if(checkForm()){
			document.assessmentTypeForm.action = "./assessmentType.do?action=submitSettings";
			document.assessmentTypeForm.target = "main";
			document.assessmentTypeForm.submit();
		}
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='common.message.addSuccess'/>");
		}
		
		var rObjs = document.getElementsByName("maxLimitCode");
		if(rObjs[2].checked){
			document.getElementById("frmRole").style.display = "block";
		}
		
		var isExpUser = document.getElementById("isExpUser");
		if(isExpUser.checked){
			document.getElementById("frmUser").style.display = "block";
			var userIds = document.getElementsByName("userId");
			var sUserIds = document.getElementById("sUserIds");
			if(sUserIds.value != "" && userIds != ""){
				var strUserIds = (sUserIds.value).split(",");
				for(var i = 0; i < strUserIds.length; i++){
					for(var j = 0; j < userIds.length; j++){
						if(strUserIds[i] == userIds[j].value){
							userIds[j].checked = true;
						}
					}
				}
			}
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="assessmentTypeForm" action="" method="post">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key="astype.title.main"/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<a href="javascript:save();" title="<fmt:message key='common.button.save'/>" hidefocus="true"><fmt:message key='common.button.save'/></a>
						</td>
						<td></td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table2" cellpadding="0" cellspacing="0" >
					<tr>
						<td>
							<table class="table_lab" cellpadding="0" cellspacing="0">
								<tr>
									<td class="title">
										业绩目标考核方式
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style1">
											<tr>
												<td class="title4" width="8%"><fmt:message key='common.lable.checkbox'/></td>
												<td class="title4"><fmt:message key='astype.title.main'/></td>
											</tr>
											<c:forEach var="target" items="${targets}">
											<c:choose>
												<c:when test="${target.nameKey2 == null || target.nameKey2 == ''}">
												<tr>
													<td align="center"><input id="targetCode" name="targetCode" type="radio" <c:if test='${target.status == 1}'>checked</c:if> value="${target.code}"/></td>
													<td><fmt:message key="${target.nameKey}"/></td>
												</tr>
												</c:when>
												<c:otherwise>
													<tr>
													<td align="center"><input id="targetCode" name="targetCode" type="radio" <c:if test='${target.status == 1}'>checked</c:if> value="${target.code}"/></td>
													<td>
														<fmt:message key="${target.nameKey}"/>
														<input id="grossProfit" name="grossProfit" class="input1" type="text" size="6" value="${target.MValue}" onkeyup="onlyNumFloat(this)"/>%
														<fmt:message key="${target.nameKey2}"/>
													</td>
												</tr>
												</c:otherwise>
											</c:choose>
											</c:forEach>
										</table><br><br>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
								<tr>
									<td>
										<table class="table_lab" cellpadding="0" cellspacing="0">
											<tr>
												<td class="title">
													保护客户上限设定
												</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td>
										<table class="table_style1">
											<tr>
												<td class="title4" width="8%"><fmt:message key='common.lable.checkbox'/></td>
												<td class="title4"><fmt:message key='astype.title.main'/></td>
											</tr>
											<c:forEach var="maxLimit" items="${maxLimits}">
												<c:if test="${maxLimit.code == 'isUnify'}">
													<tr>
														<td align="center">
															<input id="maxLimitCode" name="maxLimitCode" type="radio" <c:if test='${maxLimit.status == 1}'>checked</c:if> 
																onclick="switchSysBar(this,'frmRole')" value="${maxLimit.code}"/>
														</td>
														<td>
															<fmt:message key='${maxLimit.nameKey}'/>
															<input id="unifyLimit" name="unifyLimit" class="input1" type="text" size="6" value="${maxLimit.MValue}" onkeyup="onlyNumber(this)"/>
														</td>
													</tr>
												</c:if>
												<c:if test="${maxLimit.code == 'isTarget'}">
													<tr>
														<td align="center">
															<input id="maxLimitCode" name="maxLimitCode" type="radio" <c:if test='${maxLimit.status == 1}'>checked</c:if> 
																onclick="switchSysBar(this,'frmRole')" value="${maxLimit.code}"/>
														</td>
														<td>
															<fmt:message key='${maxLimit.nameKey}'/>
															<input id="targetLimit" name="targetLimit" class="input1" type="text" size="6" value="${maxLimit.MValue}" onkeyup="onlyNumFloat(this)"/>%
														</td>
													</tr>
												</c:if>
												<c:if test="${maxLimit.code == 'isRole'}">
													<tr>
														<td align="center">
															<input id="maxLimitCode" name="maxLimitCode" type="radio" <c:if test='${maxLimit.status == 1}'>checked</c:if> 
																onclick="switchSysBar(this,'frmRole')" value="${maxLimit.code}"/>
														</td>
														<td><fmt:message key='${maxLimit.nameKey}'/></td>
													</tr>
												</c:if>
											</c:forEach>
											<tr style="display: none;">
												<td></td>
												<td></td>
											</tr>
											<tr id="frmRole" style="display: none;">
												<td></td>
												<td width="300">
													<table class="table_style" style="text-align: center;">
														<tr>
															<td class="title4"><fmt:message key='role.lable.roleName'/></td>
															<td class="title4" width="60"><fmt:message key='role.lable.maxLimitNum'/></td>
														</tr>
														<c:forEach var="role" items="${roles}" varStatus="r">
														<tr>
															<td>${role.roleName}</td>
															<td>
																<input id="roleLimit" name="roleLimit" class="input2" type="text" value="${role.maxLimitNum}" onkeyup="onlyNumber(this)"/>
																<input id="roleId" name="roleId" class="input2" type="hidden" value="${role.id}"/>
															</td>
														</tr>
														</c:forEach>
													</table>
												</td>
											</tr>
											<c:forEach var="maxLimit" items="${maxLimits}">
												<c:if test="${maxLimit.code == 'isExpUser'}">
												<tr>
													<td align="center">
														<input id="isExpUser" name="isExpUser" type="checkbox" <c:if test='${maxLimit.status == 1}'>checked</c:if> 
															onclick="switchSysBar2(this,'frmUser')" value="${maxLimit.code}"/>
														<input id="sUserIds" name="sUserIds" type="hidden" value="${maxLimit.MValue}"/>
													</td>
													<td>例外用户</td>
												</tr>
												</c:if>
											</c:forEach>
											<tr style="display: none;">
												<td></td>
												<td></td>
											</tr>
											<tr id="frmUser" style="display: none;">
												<td></td>
												<td width="300">
													<div style="width:100%;height:150px;overflow-x: hidden;overflow-y: scroll;">
													<table class="table_style" style="text-align: center;">
														<tr>
															<td class="title4" width="50">选择</td>
															<td class="title4" width="125">用户名称</td>
															<td class="title4" width="125">部门名称</td>
														</tr>
														<c:forEach var="user" items="${users}">
														<tr>
															<td><input id="userId" name="userId" type="checkbox" value="${user.id}"/></td>
															<td>${user.userName}</td>
															<td>${user.deptName}</td>
														</tr>
														</c:forEach>
													</table>
													</div>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>